package com.dingwei.lesyndrome.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dingwei.lesyndrome.R;
import com.dingwei.lesyndrome.app.MyApplication;
import com.dingwei.lesyndrome.bean.MainBean;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.utils.DisplayUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created time 2018/2/24.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class RecommendAdapter extends RecyclerArrayAdapter<MainBean.DataBean.PerCateListBean> {
    public RecommendAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new RecommendHolder(parent);
    }

    public class RecommendHolder extends BaseViewHolder<MainBean.DataBean.PerCateListBean> {

        @Bind(R.id.img)
        ImageView mImg;
        @Bind(R.id.tv_name)
        TextView mTvName;
        @Bind(R.id.layout)
        LinearLayout mLayout;

        public RecommendHolder(ViewGroup parent) {
            super(parent, R.layout.item_recommend_type);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void setData(MainBean.DataBean.PerCateListBean data) {
            super.setData(data);
            mTvName.setText(data.name);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            if (getDataPosition() == (getAllData().size()-1)){
                lp.setMargins(DisplayUtil.dip2px(BaseActivity.context,16), 0, DisplayUtil.dip2px(BaseActivity.context,16), 0);
                mLayout.setLayoutParams(lp);
            }else {
                lp.setMargins(DisplayUtil.dip2px(BaseActivity.context,16), 0,0, 0);
                mLayout.setLayoutParams(lp);
            }

            Glide.with(BaseActivity.context)
                    .load(data.icon)
                    .apply(MyApplication.options_no_transform_no_centerCrop)
                    .into(mImg);
        }
    }
}
